package com.wangdao.wechatmall.controller.wx;

import com.wangdao.wechatmall.bean.vo.admin.BaseRespVo;
import com.wangdao.wechatmall.bean.vo.wx.dto.FootprintListDTO;
import com.wangdao.wechatmall.bean.vo.wx.WXFootprintVO;
import com.wangdao.wechatmall.service.wx.WXFootprintListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * WXFootprintController
 * created by feng on 7/12/21
 */
@RestController
@RequestMapping("wx/footprint")
public class WXFootprintController {

    @Autowired
    WXFootprintListService wxFootprintListService;
    //http://192.168.0.103:8083/wx/footprint/list?page=1&size=10

    @GetMapping("list")
    public BaseRespVo list(@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
        List<FootprintListDTO> footprintListDTOList = wxFootprintListService.selectFootprintList(page, size);

        WXFootprintVO wxFootprintVO = new WXFootprintVO();
        wxFootprintVO.setFootprintList(footprintListDTOList);
        wxFootprintVO.setTotalPages(footprintListDTOList.size());

        return BaseRespVo.ok(wxFootprintVO);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Integer id = (Integer) map.get("id");

        Integer affectRow = wxFootprintListService.delete(id);
        if(affectRow == 1){
            return BaseRespVo.ok("成功");
        }
        return BaseRespVo.fail("错误");
    }


}